// pages/guest/store/afterSearch/afterSearch.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    value:null,
    listData:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      console.log(options)
      let that = this 
      
      that.setData({
        value:options.value
      })
      that.searchStore(options.value)
  },

   searchStore:function(key){
    wx.showLoading()
    if(key==''){
      wx.showToast({
        title: '请输入关键字',
        icon:'none'
      })
      wx.hideLoading()
    }else{
      wx.cloud.callFunction(
        {
          name:'searchByKey',
          data:{
            value:key
          },success: res => {
            console.log(res)
            this.setData({
              listData:res.result.data
            })
            wx.hideLoading()
          }
        })
    }
   },
   onSearch(e){
    console.log(e.detail)
    let that = this
    if(e.detail==''){
      this.setData({
        listData:''
      })
    }else{
      that.searchStore(e.detail)
    }
},
handleTuinaDetail(ev) {
  //console.log(ev)
  let id = ev.target.dataset.id;
  wx.navigateTo({
    url: '/pages/guest/store/tuinaDetail/tuinaDetail?id=' + id
  })
 },
handleMedicDetail(ev) {
  let id = ev.target.dataset.id;
  wx.navigateTo({
    url: '/pages/guest/store/medicDetail/medicDetail?id=' + id
  })
}, handleSidelineDetail(ev) {
  let id = ev.target.dataset.id;
  wx.navigateTo({
    url: '/pages/guest/store/sidelineDetail/sidelineDetail?id=' + id
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})